package com.ruoyi.common.utils;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 描述：字符串和List类型相互转换
 * @author Cymal
 * @date 2024-03-24
 */
public class StringListUtil {

    /**
     * 逗号
     */
    public static final String SEPARATOR_COMMA = ",";

    /**
     * 描述：字符串转换为List
     * @author Cymal
     * @date 2024-03-24
     */
    public static List<String> toList(String content, String separaotor) {
        if (StringUtils.isBlank(content)) {
            return CollectionUtil.newArrayList();
        }
        String[] array = content.split(separaotor);
        if (ArrayUtil.isEmpty(array)) {
            return CollectionUtil.newArrayList();
        }
        return Arrays.asList(array);
    }

    /**
     * 描述：List转换为字符串
     * @author Cymal
     * @date 2024-03-31
     */
    public static String toString(List<String> list, String separaotor) {
        return StringUtils.join(list, separaotor);
    }

}
